import { getUserInfo } from '../../services/user';
var app = getApp()
Page({
  data: {
    canIUseAuthButton: true,
    userInfo: {},
    // currentUser: {
    //   avatar: 'https://img.gegejia.com/img/412da0075638397e361904d687432ad4.png',
    //   nickName: '糙米苏打0905',
    // },

    location: {},
    entries: [
      {
        id: 1,
        title: '待付款',
        cover:
          'https://img.gegejia.com/img/0f21f805896a8ecc55e45660f600fbc9.png',
      },
      {
        id: 2,
        title: '待发货',
        cover:
          'https://img.gegejia.com/img/0a015181e6ab6a0e7043bd3a44ee3061.png',
      },

      {
        id: 3,
        title: '租用中',
        cover:
          'https://img.gegejia.com/img/2c71d7f0fddda943eb557130727357a4.png',
      },
      {
        id: 4,
        title: '已完成',
        cover:
          'https://img.gegejia.com/img/2803dbc1ed33cf0a31974d2e01a4f0c5.png',
      },
    ],
    servers: [[{
      title: '优惠券',
      cover:
        'https://img.gegejia.com/img/92e258e1e8a4205d89952a4aba7dd9ec.png',
      url: '/pages/my-ticket/my-ticket'
      // onClick: () =>
      //   my.navigateTo({
      //     url: '/pages/my-ticket/my-ticket',
      //   }),
    },
    {
      title: '产品建议',
      cover:
        'https://img.gegejia.com/img/84465cf96e731118de0ca36e4c1e2e02.png',
      url: '/pages/consult/consult'
    },

    {
      title: '领券中心',
      cover:
        'https://img.gegejia.com/img/904b590cd67bd6f40765a995de024669.png',
      url: '/pages/get-ticket/get-ticket'

    },
    {
      title: '我的地址',
      cover:
        'https://img.gegejia.com/img/b72a21744e93ce31141b025673da788f.png',
      url: '/pages/shipping/shipping'
    },
      // {
      //   title: '投诉与建议',
      //   cover:
      //     'https://img.gegejia.com/img/f3204bcb6f675daec2a6a585f4665c0f.png',
      //   url: '/pages/consult/consult'
      // },
    ],


    ],
    navList: [
      {
        name: '我的订单',
        thumb:
          'https://gw.alipayobjects.com/mdn/rms_107da2/afts/img/A*Y8BATYqMN78AAAAAAAAAAABkARQnAQ',
        onClick: () =>
          my.navigateTo({
            url: '/pages/my-order/my-order',
          }),
      },
      {
        name: '我的券',
        thumb:
          'https://gw.alipayobjects.com/mdn/rms_107da2/afts/img/A*9RqXQaxLeCEAAAAAAAAAAABkARQnAQ',
        onClick: () =>
          my.navigateTo({
            url: '/pages/my-ticket/my-ticket',
          }),
      },
      {
        name: '关于',
        thumb:
          'https://gw.alipayobjects.com/mdn/rms_107da2/afts/img/A*-Lp1TZDggnoAAAAAAAAAAABkARQnAQ',
        onClick: () => { },
      },
    ],
  },
  onShow() {
    my.setNavigationBar({
      title: '',
      backgroundColor: '#4BA3F9'
    })
    this.setData({ userInfo: app.globalData.userInfo })
    console.log(this.data.userInfo)
  },
  onLoad() {
    this.getUserInfo()
  },
  toKf() {
    my.switchTab({
      url: '/pages/customer/customer',
    })
  },
  toOrder(event) {
    my.navigateTo({
      url: '/pages/my-order/my-order?orderStatus=' + event.target.dataset.id
    })
  },
  onListClick({ target: { dataset } }) {
    const { onClick } = this.data.navList[dataset.index];
    if (onClick) {
      onClick();
    }
  },
  // onGetAuthorize(res) {
  //   my.getPhoneNumber({
  //     success: (res) => {
  //       let encryptedData = res.response;
  //       console.log(res)
  //       my.request({
  //         url: '你的后端服务端',
  //         data: encryptedData,
  //       });
  //     },
  //     fail: (res) => {
  //       console.log(res);
  //       console.log('getPhoneNumber_fail');
  //     },
  //   });
  // },
  onGetAuthorize(res) {
    my.getOpenUserInfo({
      fail: (res) => {
        console.log(res)
      },
      success: (res) => {
        userInfo
        let userInfo = JSON.parse(res.response).response // 以下方的报文格式解析两层 response
        app.globalData.userInfo = userInfo
        this.setData({ userInfo: userInfo })
      }
    });
  },
  getLocation() {
    var that = this;
    my.showLoading();
    my.getLocation({
      type: 1,
      success(res) {
        my.hideLoading();
        console.log(res)
        that.setData({
          location: res
        })
      },
      fail() {
        my.hideLoading();
        my.alert({ title: '定位失败' });
      },
    })
  },
  entriesTap(event) {
    console.log(event)
    if (event.target.dataset.url) {
      my.navigateTo({
        url: event.target.dataset.url
      })
    }
  },
  getUserInfo() {
    getUserInfo({}).then((res) => {
      console.log(res)
      if (res.code == "000000") {

      }
    })
  },
  contract() {
    let flowId = 'b0a94bc8288b41bbbbaaec67e63b41ea'
    let accountId = '920f4c357e004a8d9b161dac561dd453'
    my.navigateTo({
      url: 'plugin://esign/esign?env=prod&flowId=' + flowId + '&signerId=' + accountId + '&skipResult=true&skipGuide=false'
    })
  },
});
